package com.godpaper.as9.commands
{
	import assets.EmbeddedAssets;
	
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.view.ViewLocator;
	import com.godpaper.as9.bussiness.delegates.UserDelegate;
	import com.godpaper.as9.events.TrySignUpEvent;
	import com.godpaper.as9.model.UserModelLocator;
	import com.godpaper.as9.view.MainPanelHelper;
	
	import mx.controls.Alert;
	import mx.events.CloseEvent;
	import mx.rpc.IResponder;

	public class TrySignUpCommand extends CommandBase implements ICommand, IResponder
	{
		private var delegate:UserDelegate;
		private var userModel:UserModelLocator = UserModelLocator.getInstance();
		private var trySignUpEvent:TrySignUpEvent;
		public function TrySignUpCommand()
		{
			delegate = new UserDelegate(this);
		}

		override public function execute(event:CairngormEvent):void
		{
			trySignUpEvent = TrySignUpEvent(event);
			delegate.create(trySignUpEvent.userVO);
		}
		
		override public function result(data:Object):void
		{
			if(data.result.info=="success")
			{
				userModel.simpleUser.email = trySignUpEvent.userVO.email;
				userModel.simpleUser.password = trySignUpEvent.userVO.password;
				Alert.show("注册用户成功！",null,4,null,closeHandler,EmbeddedAssets.ALERT_WARNNING,4);
			}
		}
		
		internal function closeHandler(event:CloseEvent):void
		{
			userModel.step = userModel.STEP_LOGIN;			
		}
	}
}